﻿@using Webdiyer.WebControls.Mvc
@using HiLand.General.Entity
@using HiLand.Utility4.MVC
@using GBFinance.Entity
@using GBFinance.Web.Models
@using HiLand.General
@using HiLand.Utility4.MVC.Data
@using HiLand.Framework.BusinessCore;
@using HiLand.Utility.Enums;
@model PagedList<BusinessUser>
@{
    ViewBag.Title = "Broker List";
    string queryName = this.GetPassedParam("queryName");
    string queryValue = this.GetPassedParam("queryValue");

    string brokerListUrl = Url.Action("Index", "Broker");
}
<style type="text/css">
    .modalFix
    {
        width: 650px;
    }
</style>
<h2>
    Broker List</h2>
<div id="ItemListDIV">
    @using (Html.BeginForm())
    {
        <select name="queryConditionName" id="queryConditionName">
            <option value="">Please select...</option>
            @if (queryName == "CustomerNo")
            {
                <option value="CustomerNo" selected="selected">Customer No.</option>
            }
            else
            { 
                <option value="CustomerNo">Customer No.</option>
            }
            @if (queryName == "FirstName")
            {
                <option value="FirstName" selected="selected">First Name</option>
            }
            else
            { 
                <option value="FirstName">First Name</option>
            }
            @if (queryName == "LastName")
            {
                <option value="LastName" selected="selected">Last Name</option>
            }
            else
            { 
                <option value="LastName">Last Name</option>
            }
            @if (queryName == "PhoneNumber")
            {
                <option value="PhoneNumber" selected="selected">Phone Number</option>
            }
            else
            { 
                <option value="PhoneNumber">Phone Number</option>
            }
            @if (queryName == "Email")
            {
                <option value="Email" selected="selected">Email</option>
            }
            else
            { 
                <option value="Email">Email</option>
            }
            @if (queryName == "Stopped")
            {
                <option value="Stopped" selected="selected">Stopped</option>
            }
            else
            { 
                <option value="Stopped">Stopped</option>
            }
            @if (queryName == "Deleted")
            {
                <option value="Deleted" selected="selected">Deleted</option>
            }
            else
            { 
                <option value="Deleted">Deleted</option>
            }
        </select>
        <input name="queryConditionValue" id="queryConditionValue" value="@queryValue" />
        <input type="button" id="btnQuery" value="Query" />
    }
    <table width="98%" class="grid">
        <tr>
            <th style="width: 70px">
                Operate
            </th>
            <th style="width: 30px">
                Costom No.
            </th>
            <th style="width: 80px">
                Broker Name
            </th>
            <th style="width: 80px">
                Password
            </th>
            <th style="width: 60px">
                Email
            </th>
            <th style="width: 60px">
                Create Date
            </th>
        </tr>
        @foreach (BusinessUser entity in Model)
        {
            <tr>
                <td>
                    @if (entity.UserStatus == UserStatuses.Normal)
                    { 
                        <a href="#" class="stopItem"  itemGuid="@entity.UserGuid">Stop</a>
                        <a href="#" class="deleteItem"  itemGuid="@entity.UserGuid">Delete</a>
                        <a href="#" class="modalInput editItem" rel="#editItemDIV"  itemGuid="@entity.UserGuid">
                            Edit</a>
                    }
                    else
                    {
                        <a href="#" class="recoverItem"  itemGuid="@entity.UserGuid">Recover</a>
                    }
                </td>
                <td>@entity.UserID
                </td>
                <td>@entity.UserName
                </td>
                <td>@entity.Password
                </td>
                <td>@entity.UserEmail
                </td>
                <td>@entity.UserRegisterDate.ToString(Miscs.DateTimeFormating)
                </td>
            </tr>   
        }
    </table>
    <div class="modal modalFix" id="editItemDIV">
    </div>
    @Html.Pager(Model, new PagerOptions() { PageIndexParameterName = "id", ShowDisabledPagerItems = false, AlwaysShowFirstLastPageNumber = true })
    <script type="text/javascript">
        $(document).ready(function () {
            $("#aBrokerSection").addClass("current");
            $("#aBrokerList").addClass("current");

            $(".modalInput").overlay({
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },
                closeOnClick: false
            });

            $("a.editItem").click(function () {
                var targetID = $(this).attr("itemGuid");
                //var url = '@Url.Action("_BrokerInformation", "Account", new { area = "Broker" })' + '?brokerGuid=' + targetID + '&r=' + Math.random();
                var url = $.UrlUtil('@Url.Action("_BrokerInformation", "Account", new { area = "Broker" })').concat("brokerGuid", targetID).concat("isDisplaySubmitButton", true).show(true);
                $("#editItemDIV").load(url);
            });

            $("a.deleteItem").click(function () {
                var result = confirm("need delete this record?");
                if (result == true) {
                    var targetID = $(this).attr("itemGuid");
                    var url = '@Url.Action("SetBrokerStatusToUnnormal")';
                    $.post(url, { userGuid: targetID }, function (data) {
                        window.location.reload();
                    });
                }
            });

            $("a.stopItem").click(function () {
                var result = confirm("need stop this record?");
                if (result == true) {
                    var targetID = $(this).attr("itemGuid");
                    var url = '@Url.Action("SetBrokerStatusToStop")';
                    $.post(url, { userGuid: targetID }, function (data) {
                        window.location.reload();
                    });
                }
            });

            $("a.recoverItem").click(function () {
                var result = confirm("need recover this record?");
                if (result == true) {
                    var targetID = $(this).attr("itemGuid");
                    var url = '@Url.Action("SetBrokerStatusToNormal")';
                    $.post(url, { userGuid: targetID }, function (data) {
                        window.location.reload();
                    });
                }
            });

            $("#btnQuery").click(function () {
                var queryName = $("#queryConditionName").val();
                var queryValue = $("#queryConditionValue").val();
                var url = '@brokerListUrl' + '?queryConditionName=' + queryName + '&queryConditionValue=' + queryValue;
                window.location = url;
            });
        });
    </script>
</div>
